<%@page import="leave.dataaccess.LeaveDAO"%>
<%@page import="leave.dataaccess.DAOFactory"%>
<%@page import="leave.dataaccess.EmployeeLeaveDAO"%>
<%@page import="leave.model.impl.mysql.EmployeeImpl"%>
<%@page import="leave.model.*"%>
<%@page import="leave.model.impl.mysql.ManagerImpl"%>
<%@page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<fmt:setBundle basename="TextForManagerPage" />
<title><fmt:message key="approveleave.title"/></title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<form method="post">
<%
/*EmployeeLeaveDAO empDAO = DAOFactory.getInstance().getEmployeeLeaveDAO();
Manager manager = (ManagerImpl) empDAO.getEmployee(2);
Leave[] leaves = manager.getPendingLeave();
ArrayList<Leave> leaveList = new ArrayList<Leave>();
for(int j=0; j<leaves.length && leaves != null; j++)
{
	leaveList.add(leaves[j]);
}*/

EmployeeLeaveDAO employeeLeaveDAO = DAOFactory.getInstance().getEmployeeLeaveDAO();
LeaveDAO leaveDAO = DAOFactory.getInstance().getLeaveDAO();
//need to change employee id
ArrayList<Employee> employees = employeeLeaveDAO.getSubordinateEmployee(2);
ArrayList<Leave> leaveList = new ArrayList<Leave>();
for(int i=0; i<employees.size() && employees != null; i++)
{
	Leave[] leaves = leaveDAO.getPendingLeaveTransactions(employees.get(i));
	for(int j=0; j<leaves.length && leaves != null; j++)
	{
		leaveList.add(leaves[j]);
	}
}
%>
<table width="100%">
<tr>
<td class="title" align="left" colspan="6" height="40px"><fmt:message key="approveleave.title"/></td>
</tr>
<tr bgcolor="#66cc66">
<td width="10%" class="header"><fmt:message key="approveleave.leaveid"/></td>
<td width="20%" class="header"><fmt:message key="approveleave.leavetype"/></td>
<td width="20%" class="header"><fmt:message key="approveleave.appliedby"/></td>
<td width="20%" class="header"><fmt:message key="approveleave.startdate"/></td>
<td width="20%" class="header"><fmt:message key="approveleave.enddate"/></td>
<td width="10%" class="header"></td>
</tr>
<%
//for(int i=0; i<leaveList.length && leaves != null; i++)
if(leaveList.size() > 0)
{
for(int i=0; i<leaveList.size(); i++)
{
%>
<tr>
<td width="10%" class="list"><%=leaveList.get(i).getLeaveID() %></td>
<td width="20%" class="list"><%=leaveList.get(i).getLeaveType() %></td>
<td width="20%" class="list"><a href="xxx.jsp?empID=<%=leaveList.get(i).getAppliedBy()%>"><%=leaveList.get(i).getAppliedBy().getName() %></a></td>
<td width="20%" class="list"><%=leaveList.get(i).getStartDate() %></td>
<td width="20%" class="list"><%=leaveList.get(i).getEndDate() %></td>
<td width="10%" class="list"><a href="ApproveLeavesDetails.jsp?leaveID=<%=leaveList.get(i).getLeaveID()%>"><fmt:message key="form.details"/></a></td>

</tr>
<%
}
}
else
{
%>
<tr>
<td colspan="6" class="list" align="center"><fmt:message key="form.notfound"><fmt:param><fmt:message key="approveleave.pending"/></fmt:param></fmt:message></td>
</tr>
<%
}
%>
</table>
</form>
</body>
</html>